package com.wwwarehouse.taskcenter.fragment.job_point.step5;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;

import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.custom_widget.keyboard.VirtualKeyboardView;
import com.wwwarehouse.common.custom_widget.popupwindow.EasyPopupWindow;
import com.wwwarehouse.common.custom_widget.state_layout.StateLayout;
import com.wwwarehouse.common.tools.PopUpUtils;
import com.wwwarehouse.common.tools.rsa.StringUtils;
import com.wwwarehouse.taskcenter.R;
import com.wwwarehouse.taskcenter.adapter.job_point.TaskPointUnitsJustshowunitAdapter;
import com.wwwarehouse.taskcenter.bean.job_point.AddJobPointStep5LookItemMesResponseBean;

import java.util.ArrayList;

/**
 * @创建者 chenchao.
 * @创建时间 2017/10/25 18:57
 * @描述 ${TODO}
 */

public class ChooseJobUnitJustShowAllunitFragment5 extends BaseFragment implements EasyPopupWindow.ChildClickListener {

    private View mView;
    private RecyclerView mTaskPointRecycleview;
    private StateLayout mSlLayout;
    private static final int pageSize = 10;
    private ArrayList<AddJobPointStep5LookItemMesResponseBean.ListBean> currentList;
    private EasyPopupWindow mEasyPopupWindow;
    private TaskPointUnitsJustshowunitAdapter adapter;
    private String currentUkid;
//    private PopupWindow popupWindow;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_choose_object_detail_6, container, false);
        initView(mView);
        return mView;
    }


    @Override
    public void setTitle() {
    }

    @Override
    public void requestDatas() {

    }

    private void initView(View mView) {
        mTaskPointRecycleview = (RecyclerView) mView.findViewById(R.id.task_point_recycleview);
        mSlLayout = (StateLayout) mView.findViewById(R.id.sl_layout);

        mTaskPointRecycleview.setLayoutManager(new LinearLayoutManager(mActivity));

        int page = getArguments().getInt("page");
        ArrayList<AddJobPointStep5LookItemMesResponseBean.ListBean> list = getArguments().getParcelableArrayList("dataList");

        currentList = new ArrayList<>();
        for (int i = (page - 1) * pageSize; i < (list.size() > page * pageSize ? page * pageSize : list.size()); i++) {
            currentList.add(list.get(i));
        }

        adapter = new TaskPointUnitsJustshowunitAdapter(currentList, mActivity,this);

        mTaskPointRecycleview.setAdapter(adapter);


    }

    public void showKeybord(String curentUkid){
        currentUkid = curentUkid;
        mEasyPopupWindow = PopUpUtils.showPopUpBottom(R.layout.popupwindow_inputboard_layout, mActivity, mActivity.findViewById(android.R.id.content), true, this);
//        popupWindow = new PopupWindow();
//        popupWindow.setContentView(View.inflate(mActivity,R.layout.popupwindow_inputboard_layout,mSlLayout));
//        popupWindow.setBackgroundDrawable(new ColorDrawable(mActivity.getResources().getColor(R.color.white)));
//        popupWindow.getBackground().setAlpha(200);
//        popupWindow.showAtLocation(mActivity.findViewById(android.R.id.content), 80, 0, 0);
    }

    @Override
    public void getChildView(int i, View view) {

        VirtualKeyboardView keyboardView = (VirtualKeyboardView) view.findViewById(R.id.number);
        keyboardView.isShowContentBar(true);
        keyboardView.setOnInputDataConfirmListener(new VirtualKeyboardView.OnInputDataConfirmListener() {
            @Override
            public void InputDataConfirm(String s) {
                if(StringUtils.isNullString(s)){
                    mEasyPopupWindow.dismiss();
                    return;
                }

                try {
                    int number = Integer.parseInt(s.trim());
                    if(number > 1 ){
                        adapter.setAdapterNumber("" + currentUkid ,number);
                        mEasyPopupWindow.dismiss();
                    }

                } catch (NumberFormatException e) {
                    toast("请输入有效数量！");
                }
            }
        });

    }

    @Override
    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
        return null;
    }
}
